package Graphique;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import Client.Client;

public class MainGraphique extends JFrame{
	private static final long serialVersionUID = 1L;
	private Client client;
	private JButton connexion = new JButton("Connexion");
	private JButton horsConnexion = new JButton("Hors Connexion");
	private JButton inscription = new JButton("Inscription");
	private JLabel texteIntro = new JLabel("Bienvenue sur Twouitter !!!");
	private ActionListenerMain alc = new ActionListenerMain();

	public MainGraphique(Client client){
		super("Accueil");
		
		this.setSize(250, 250);
		
		connexion.addActionListener(alc);
		horsConnexion.addActionListener(alc);
		inscription.addActionListener(alc);
		
		JPanel jp = new JPanel();
		jp.setLayout(new GridLayout(4, 1));
		jp.add(texteIntro);
		jp.add(connexion);
		jp.add(inscription);
		jp.add(horsConnexion);
		
		this.add(jp);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
		this.client = client;
	}

	private class ActionListenerMain implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			Object obj = e.getSource();

			if(connexion.equals(obj)){
				//Mode authentifié
				new Connexion(client);
			}	
			if(horsConnexion.equals(obj)){
				//Mode non authentifié
				new HorsConnexion(client);
			}	
			if(inscription.equals(obj)){
				//Inscription
				new Inscription(client);
			}	
			
		}
	}

}
